<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <link rel="stylesheet" th:href="@{/lib/lui/css/layui.css}">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<div class="layui-container">
<div th:html="${trafficlaw.id}"></div>
<div th:if="${edit}">
</div>
<form id="trafficlawForm" class="layui-form" action="edit" method="post">
    <input type="hidden" name="id" th:value="${trafficlaw.id}"/>
    <input type="hidden" class="imagePath" name="imagePath" th:value="${trafficlaw.imagePath}"/>
    <div class="layui-form-item">
        <label class="layui-form-label">图片</label>
        <div class="layui-input-block">
            <div class="layui-upload">
                <button type="button" class="layui-btn" id="pic">
  					<i class="layui-icon">&#xe67c;</i>上传图片</button>
                <div class="layui-upload-list">
                    <img class="layui-upload-img" id="demo1">
                    <p id="demoText"></p>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div th:if="${edit}" class="layui-input-block">
            <input  type="text" name="title" lay-verify="title" autocomplete="off" th:value="${trafficlaw.title}" placeholder="请输入标题" class="layui-input">
        </div>
        <div class="layui-form-mid" th:unless="${edit}" th:text="${trafficlaw.title}"></div>
    </div>
       
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">内容</label>
        <div th:if="${edit}" class="layui-input-block">
            <textarea class="layui-textarea" name="content" th:text="${trafficlaw.content}">
            </textarea>
        </div>
        <div class="layui-form-mid" th:unless="${edit}" th:text="${trafficlaw.content}"></div>
    </div>

</form>
</div>
<script th:src="@{/lib/jquery/jquery.js}"></script>
<script th:src="@{/lib/jquery/jquery.forms.js}"></script>
<script th:src="@{/lib/lui/layui.all.js}"></script>
<script type="text/javascript">
    $.fn.serializeObject = function()
    {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function() {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };
</script>
<script type="text/javascript">
   
    //layui.layedit.build('LAY_demo_editor');

    function doSave(fn){

        var data = $("#trafficlawForm").serializeObject();

        $.ajax("edit",{
            method:"post",
            contentType:"application/json; charset=utf-8",
            data:JSON.stringify(data),
            success:function(data) {
                if(data) {
                    parent.tips(1, "保存成功！");
                    fn.call();
                }else{
                    parent.tips(0, "保存信息失败！");
                }
            },
            error:function(e){
                parent.tips(0,e);
            }
        });

    }

</script>
<script>
	layui.use('upload', function() {
		var upload = layui.upload;
		//执行实例
		var uploadInst = upload.render({
			//绑定元素
			elem : '#pic',
			//上传接口
			url : '/demo/ops/fileupload/upload',
			//允许上传的文件类型
			accept: 'file',
			//最大允许上传的文件大小(KB),0=不限制
			size: 0,
			//成功回调
			done: function(res){
			    if(res.status == 1){
			      $("#demo1").attr("src","/demo/"+res.data);
			      $(".imagePath").val(res.data);
			    }
			},
			//失败回调
			error: function(){
				alert("上传失败");
			}
		});
	});
</script>
	
	
<script>
	 $(function(){
		 var imagePath=$(".imagePath").val();
		 if(imagePath!=""){
			 $("#demo1").attr("src","/demo/"+imagePath);
		 }
	 });
</script>
</body>
</html>